package fab.forms.fields 
{
	import fl.controls.CheckBox;
	import fab.forms.error.FormError;
	import fab.forms.fields.Element;
	/**
	 * ...
	 * @author fab
	 */
	public class CheckBoxElement extends Element
	{
		private var _cb:CheckBox;
		
		public function CheckBoxElement(cb:CheckBox, na:String=null) 
		{
			_cb = cb;
			name = na?na:cb.name;
		}
		
		
		override public function validate():FormError
		{
			var error:FormError;
			if ( hasError( FormError.CHECKED ) && !selected() )
			{
				error = getError( FormError.CHECKED );
			}
			return error;			
		}		
		private function selected():Boolean
		{
			return _cb.selected;			
		}	
		override public function getValue():String
		{
			return _cb.selected?"1":"0";
		}		
	}

}